// pages/shops/detail.js
const app = getApp();

let req = require('../../utils/request.js');
let api = require('../../utils/api.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentTab: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var id = options.id

    this.setData({ id: id })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var _this = this,
      id = _this.data.id

    wx.showLoading({
      title: '加载中',
    })

    req.request(
      api.getProductAttraction,
      { method: 'POST', data: { id: id } },
      function (res) {
        wx.hideLoading();
        res = res.data[0]
        console.info(res);
        var data = app.towxml.toJson(res.attr_description, 'markdown')
        _this.setData({article: data, info: res})
      }
    )
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  /** 
     * 滑动切换tab 
     */  
  bindChange: function (e) {

    var that = this;
    that.setData({ currentTab: e.detail.current });

  },
  /** 
   * 点击tab切换 
   */
  swichNav: function (e) {

    var that = this;

    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  } ,
  Reserve(e){
    var tic_id = e.currentTarget.id,
        _this = this,
        flt_id = e.currentTarget.dataset.flt_id,
        count = e.currentTarget.dataset.count

    if(count == 0) {
      wx.showToast({
        title: '已售空',
        icon: 'none'
      })
      return false;
    }

    wx.navigateTo({
      url: '/pages/order/index?flt_id='+flt_id+'&tic_id='+tic_id,
    })
  },
  booking() {
    var id = this.data.id
    wx.navigateTo({
      url: '/pages/order/index?id=' + id,
    })
  }
})